(function() {
	var z = window.Efast;
	//$T, $N, $V, $S, $NV, $NS, $F简短别名都在这儿配置
	z.$G = z.getDom;
	z.$T = z.getByTag;
	z.$N = z.getByName;
	if (z.Node) {
		z.$V = z.Node.getValue;
		z.$S = z.Node.setValue;
	}
	z.$NV = z.getValues;
	z.$NS = z.setValues;
	z.$F = z.getForm;
	if (!z.Config.namespace) {
		return;
	}
	if (z.Config.namespace === 'window') { //当配置项namespace为window时，把Efast下的所有对象复制到window下
		var p, skipExtra = [];
		for (p in z) {
			if (typeof(z[p]) === 'undefined' || /^(id|g)$/.test(p)) {
				continue;
			}
			if (typeof(window[p]) !== 'undefined') {
				if (!/^(\$|Object|Class|Array|Date|Function|String|Node|Event|JSON|Storage)$/.test(p)) {
					skipExtra.push('retouch.js -- ' + p + ' existed in window');
				} else if (/^(Object|Class|Array|Date|Function|String|Node|Event|JSON|Storage)$/.test(p) && typeof(z[p]) === 'object') { //如果Efast下对象和原生对象重名，则复制对象下的属性/方法
					z.mixIf(window[p], z[p]);
				}
			} else {
				try {
					window[p] = z[p];
				} catch (ex) {
					throw ex;
				}
			}
		}
		if (skipExtra.length && z.Console) {
			z.Console.silence = true; //Console的静默模式，暂存log，不直接显示在页面上
			z.Console.error(skipExtra.join('<br>'));
		}
	} else if (z.Config.namespace !== 'Efast') {
		window[z.Config.namespace] = z;
	}

	if(!window.console.dir){
		window.console.dir = function(obj) {
			if(!/object/.test(Object.prototype.toString.call(obj))){
				return console.log('console can`t dir the arg');
			}
			for(var key in obj){
				console.log(key,': ',obj[key]);
			}
		};
	}
	if (z.Config.ignoreErrors == 'true') { //忽略脚本错误
		window.onerror = function() {
			return false;
		};
	}

	/*在页面关闭时清除对dom元素的缓存，释放内存*/
	$window.on('unload', function() {
		//console.log('retouch.js#67 window unload'+(+new Date()));
		if (z.ComponentManager) {
			z.ComponentManager._unload(); //销毁所有js组件实例
		}
		if (z.AllDocumentsEvent) {
			z.AllDocumentsEvent._unload();
		}
		
		//2013-11-27 清除掉所有有通过jQuery注册事件的元素的事件监听，防止内存泄漏
		var cache=jQuery.cache;
		var el,toRemove=[];
		for(var id in jQuery.cache){
			if(cache[id].handle && (el=cache[id].handle.elem)){
				if(el.nodeName && el.nodeType==1){
					//是元素，不是Document
					toRemove.push( el );
				}
			}
			
		}
		//jQuery.cleanData(toRemove);
		toRemove=null;
		
		z.rootWin=z.rootDoc=null;
		$document.off();
		$window.off();
	});
	var skin = z.Cookie.get("backend_skin");
	if(skin){
		var stylesheets=document.getElementsByTagName('link');
		for(var i=0,l=stylesheets.length;i<l;i++){
			var href=stylesheets[i].href;
			if(href && href.endsWith(z.CONTEXTPATH+'style/default.css')){
				//引用了style/default.css后，认为是在后台系统中这时才允许使用皮肤样式
				z.Config.skin= skin;
				z.importCSS('../style/'+skin+'/default.css');
				break;
			}
		}
	}

})();
Efast.Skin={};
Efast.Skin.Supported='classic';

Efast.Lang = Efast.Lang || {};
Efast.Lang.Supported = "en,zh-cn,zh-tw";
Efast.Lang.DefaultLanguage = "zh-cn";
